# Compiler and flags
CXX = g++
CXXFLAGS = -std=c++11 -pthread -L/usr/lib64/mysql -lmysqlclient -lhiredis -lcryptopp
# CXXFLAGS = -std=c++11 -pthread -L/usr/lib64/mysql -lmysqlclient -g

# Directories
SRC_DIR = .
INC_DIRS = http_conn locker pool timer log mysql_conn
OBJ_DIR = obj
BIN_DIR = bin

# Source files
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
SRCS += $(wildcard $(addsuffix /*.cpp,$(INC_DIRS)))

# Object files
OBJS = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS))

# Binary name
TARGET = $(BIN_DIR)/webserver

# Include directories
INC_FLAGS = $(addprefix -I, $(INC_DIRS))

# Rules
.PHONY: all clean

all: clean $(TARGET)
	@rm -rf $(OBJ_DIR)

$(TARGET): $(OBJS)
	@mkdir -p $(BIN_DIR)
	$(CXX) $(CXXFLAGS) -o $@ $^

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	@mkdir -p $(OBJ_DIR)
	$(CXX) $(CXXFLAGS) $(INC_FLAGS) -c -o $@ $<

clean:
	rm -rf $(OBJ_DIR) $(BIN_DIR)
